﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace W1_MenuGame
{
    public abstract class VisibleGameObject
    {
        protected List<My2DSprite> _sprites;

        public List<My2DSprite> Sprites
        {
            get { return _sprites; }
            set { _sprites = value; }
        }


        protected int _currentSprite;

        public int CurrentSprite
        {
            get { return _currentSprite; }
            set { _currentSprite = value; }
        }

        protected Vector2 _position;

        public Vector2 Position
        {
            get { return _position; }
            set { _position = value; }
        }

        public VisibleGameObject()
        {
            _sprites = new List<My2DSprite>();
            _currentSprite = -1;
            _position = Vector2.Zero;
        }

        public virtual void Initialize(ContentManager content, List<KeyValuePair<string, int>> pathResources, Vector2 position)
        {
            foreach (KeyValuePair<string, int> path in pathResources)
            {
                List<Texture2D> lstTextures = new List<Texture2D>();

                for (int i = 0; i < path.Value; i++)
                {
                    lstTextures.Add(content.Load<Texture2D>(path.Key + (i + 1).ToString("00")));
                }

                My2DSprite newSpr = new My2DSprite();

                InitializeSprite(ref newSpr, lstTextures, position);

                _sprites.Add(newSpr);
            }

            if (_sprites.Count > 0)
            {
                _currentSprite = 0;
            }
        }

        protected virtual void InitializeSprite(ref My2DSprite newSpr, List<Texture2D> lstTextures, Vector2 position)
        {
            return;
        }

        public virtual void Update(GameTime gameTime)
        {
            _sprites[_currentSprite].Update(gameTime);
        }

        public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            //Vẽ animation Sprite ở đây
            _sprites[_currentSprite].Draw(gameTime, spriteBatch);
        }
    }
}
